﻿Imports System.Xml.Serialization
Imports Org.BouncyCastle.X509
Imports Org.BouncyCastle.Crypto
Imports Org.BouncyCastle.Crypto.Parameters
Imports Org.BouncyCastle.Asn1.Pkcs
Imports Org.BouncyCastle.Pkcs
Imports Org.BouncyCastle.Security
Imports SharedTools
Imports System.Collections.ObjectModel

Public Class ClientProfile
    Public Property Name As String
    Public Property Surname As String
    Public ReadOnly Property FullName As String
        Get
            Return Name & " " & Surname
        End Get
    End Property
    Public Property Organization As String
    Public Property OragnizationUnit As String
    Public Property Country As String
    Public Property eMailAddress As String

    Public Property KeyLength As Integer

    Public Property UserName As String

    Public ReadOnly Property WaitingForSigCert As Boolean
        Get
            Return SigCert IsNot Nothing AndAlso SigCert.OriginalRequest IsNot Nothing AndAlso SigCert.Certificate Is Nothing
        End Get
    End Property

    Public ReadOnly Property WaitingForCryptoCert As Boolean
        Get
            Return CryptoCert IsNot Nothing AndAlso CryptoCert.OriginalRequest IsNot Nothing AndAlso CryptoCert.Certificate Is Nothing
        End Get
    End Property

    Public Property SigCert As CertificateItem = Nothing
    Public Property CryptoCert As CertificateItem = Nothing


    Public Property OldCertificates As ObservableCollection(Of CertificateItem)

    <XmlIgnore()> Public Property LocalCRL As X509Crl
    Public Property SerializableLocalCRL As Byte()
        Get
            Try
                Return LocalCRL.GetEncoded
            Catch ex As Exception
                Return Nothing
            End Try
        End Get
        Set(value As Byte())
            Try
                Dim parser = New X509CrlParser
                LocalCRL = parser.ReadCrl(value)
            Catch ex As Exception
                LocalCRL = Nothing
            End Try
        End Set
    End Property

    <XmlIgnore()> Public ReadOnly Property DistinguishedName As String
        Get
            Return "CN=" & FullName & ", O=" & Organization & ", OU=" & OragnizationUnit & ", C=" & Country & ", UID=" & UserName
        End Get
    End Property


    Public Class KeysNotReadyException
        Inherits Exception
    End Class
End Class
